package com.devicemantra.coordinate.dataobjects;

import java.util.UUID;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.datastore.Sequence;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="true")
public class CLocation 
{
	@PrimaryKey
    @Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key mLocationKey;
	
	@Persistent(defaultFetchGroup="true")
	CPoint mPoint;
	
	
	@Persistent(defaultFetchGroup="true")
	private CDepartment mMappedDepartment;
	
	@Persistent(defaultFetchGroup="true")
	private String mDepartment;
	
	@Persistent
	String mEmirate;
	
	@Persistent
	String mAddress = null;
	
	@Persistent
	String mLocationDesc="NA";
	
	@Persistent(defaultFetchGroup="true")
	String mLocationId; 
	
	public CLocation() 	{
		
	}
	
	public CLocation(CPoint pPoint,  String pLocationDesc)
	{
		mPoint = pPoint;
		mLocationDesc = pLocationDesc;
		mAddress = " ";
	}
	
	/* Package level access only for this constructor */
	public CLocation(Double pLatitude,
			  Double pLongitude,
			  String pDeptName,
			  String pStateName,
			  String pAddress,
			  String pLocationDesc)
	{
		mPoint = new CPoint(pLatitude,pLongitude);
		mLocationDesc = pLocationDesc;
		mAddress = pAddress;
		mDepartment = pDeptName;
		mEmirate = pStateName;
	}
	
	
	
	/**
	 * @return the mPoint
	 */
	public CPoint getPoint() {
		return mPoint;
	}

	/**
	 * @param mPoint the mPoint to set
	 */
	public void setPoint(CPoint mPoint) {
		this.mPoint = mPoint;
	}

	
	public String getLocationDescription()
	{
		return mLocationDesc;
	}
	
	public void setLocationDescription(String pLocationDesc)
	{
		 mLocationDesc = pLocationDesc;
	}
	
	public CDepartment getOwningDepartment()
	{
		if( mMappedDepartment != null)
			return mMappedDepartment;
		else
			return null;
	}
	
	public String getDepartmentName()
	{
		return mDepartment;
	}



	public String getEmirate() {
		return mEmirate;
	}



	public void setEmirate(String pEmirate) {
		this.mEmirate = pEmirate;
	}
	
	public String getAddress() {
		return mAddress;
	}



	public void setAddress(String pAddress) {
		this.mAddress = pAddress;
	}
	
	public String getLatitude()
	{
		return mPoint.getLatitude().toString();
	}
	
	public String getLongitude()
	{
		return mPoint.getLongitude().toString();
	}
	
	public String getLogoUrl()
	{
		return mMappedDepartment.getLogo().getUrl();
	}
	
	public String getLocationId()
	{
		return mLocationId;
	}
	
	public void setLocationId(String pLocationId)
	{
		mLocationId = pLocationId;
	}
	
	public CPoint getLocation()
	{
		return mPoint;
	}
	
}